<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_cmdemp-" . date("Y-m-d") . ".log";


$emp_id = $_REQUEST['emp_id'];
$emp_name = $_REQUEST['emp_name'];
$pos_id = $_REQUEST['pos_id'];
$province_id = $_REQUEST['province_id'];
$mobile = $_REQUEST['mobile'];
$flagsp = $_REQUEST['flagsp'];
$action = $_REQUEST['action'];

writelog($logfile, "emp_id num     : " . $emp_id);
writelog($logfile, "emp_name      : " . $emp_name);
writelog($logfile, "pos_id     : " . $pos_id);
writelog($logfile, "mobile      : " . $mobile);
writelog($logfile, "province_id      : " . $province_id);
$emp_name = iconv('tis-620', 'utf-8', $emp_name);
writelog($logfile, "flagsp      : " . $flagsp);
writelog($logfile, "action   : " . $action);

if($action == "add"){
	$sql = "insert into employee(emp_name, pos_id, province_id, mobile, flag_req_spacial)values(?, ?, ?, ?, ?)";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($emp_name, $pos_id, $province_id, $mobile, $flagsp);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "add employee success!");
	}else{
		writelog($logfile, "add employee error!");
	}
}else if($action == "del"){
	$sql = "delete from employee where emp_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($emp_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "delete employee success!");
	}else{
		writelog($logfile, "delete employee error!");
	}
}else if($action == "edit"){
	$sql = "update employee set emp_name =?, pos_id=?,province_id=?, mobile=?, flag_req_spacial=?  where emp_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($emp_name, $pos_id, $province_id, $mobile, $flagsp, $emp_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "update employee success!");
	}else{
		writelog($logfile, "update employee error!");
	}
	
}


writelog($logfile, "reply : OK");
writelog($logfile, "-------------------------------------------------- ");
echo viewEmpName($db);

?>

